package main.二叉树;

import common.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author tmh
 * @date 2024/7/22 14:27
 * @description
 */
public class T230二叉搜索树中第K小的元素 {
    List<Integer> result  = new ArrayList<>();
    public int kthSmallest(TreeNode root, int k) {
        dfs(root);
        return result.get(k-1);
    }

    private void dfs(TreeNode root){
        if (root==null){
            return;
        }
        dfs(root.left);
        result.add(root.val);
        dfs(root.right);
    }
}
